package com.daiziru.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 作者：無言
 * 时间：2022/12/6 23:36
 * 描述：永无BUG
 */
@Controller
public class indexController extends BaseController{

    /**
     * 首页分页查贴子，并返回到详情页面
     * @return
     */
    @RequestMapping ({"","/","index"})
    public String index() {

        // 1分页信息 2分类 3用户 4置顶  5精选 6排序
        IPage result  = postService.selectByPage(getPage(),null, null, null, null, "created");
        req.setAttribute("pageData", result);
        req.setAttribute("currentCategoryId", 0);
        return "index";
    }

    /**
     * 搜索文章
     * @param q 输入的要搜索的关键字
     * @return
     */
    @RequestMapping("/search")
    public String search(String q) {
        IPage pageData = searchService.search(getPage(), q);
        req.setAttribute("q", q);
        req.setAttribute("pageData", pageData);
        return "search";
    }
}
